classdef net
    properties
        name
        file
        deploy_file
        log_path
        model_path
        result_path
        model_prefix
    end
    
    methods
        function o = net(net, solv, cmd, Train, Test, flag)
            if nargin < 6, flag = []; end
            %%
            o.name = net.name;
            [o.result_path, bFound] = o.getResultPath(net, solv, cmd, Train, flag);
            
            %%
            o.file = fullfile(o.result_path, [o.name '.prototxt']);
            o.deploy_file = fullfile(o.result_path, [o.name, '_deploy', '.prototxt']);
            o.log_path = fullfile(o.result_path, 'logs');
            o.model_path = fullfile(o.result_path, 'models');
            o.model_prefix = [o.name '_iter_'];
            
            %%
            if bFound && ~isfield(cmd, 'snapshot') && ~isempty(dir(fullfile(o.model_path, '*.caffemodel')))
                warning([
                    'Caffe model already exists in:\n'...
                    '    %s.\n'...
                    'Please ensure if you would like to retrain it from scratch. '...
                    'If not, please assign the "cmd.snapshot" param.'], o.model_path);
            end
            
            %%
            o.genResultPath(net, bFound, Train, Test);
        end
    end
    
    methods(Static)
        createDeployNet(net_file, deploy_file)
        
        path = rmExpPath(path, result_path)
        varargout = rmUnnecessaryFields(varargin)
        
        [net_result_path, bFound] = getResultPath(net, solv, cmd, Train, flag)
        
        net = parseWeightInitParam(net)
        net_content = setName(net_content, net_name)
        new_content = setTrainTest(net_content, Train, Test)
        
        genFile(net_file, net_content)
        
        [ii, jj] = getLayer(net_content, layer_nmae)
        net_content = rmLayer(net_content, layer_nmae)
    end
end
